//
//  DriveViewController.swift
//  jiahui
//
//  Created by 3tee on 2024/11/27.
//

import UIKit
import RxCocoa
import RxSwift
class DriveViewController: UIViewController {

    @IBOutlet weak var lab1: UILabel!
    @IBOutlet weak var tapBtn: UIButton!
    lazy var bag = DisposeBag()
    
    override func viewDidAppear(_ animated: Bool) {
        super.viewDidAppear(animated)
        print("父视图 = \(type(of: self.parent))")
        //切换到驾驶模式默认关闭麦克风和摄像头
        let parentVC: MeetingViewController =  self.parent?.parent as! MeetingViewController
        ThreeTManager.shardInstance.openMic(isOpen: false)
        ThreeTManager.shardInstance.openCamera(false)
    }
    
    override func viewDidLoad() {
        super.viewDidLoad()
        print("xxxx驾驶模式")
        tapBtn.layer.cornerRadius = 80
        tapBtn.layer.masksToBounds = true
        tapBtn.layer.borderWidth = 1
        tapBtn.layer.borderColor = UIColor.white.cgColor
        tapBtn.setTitle("轻击说话", for: .normal)
        tapBtn.setTitle("完成说话", for: .selected)

        
        tapBtn.rx.tap.subscribe {[weak self] event in
            guard let strongself = self else{ return }
            strongself.tapBtn.isSelected = !strongself.tapBtn.isSelected
            
            print("\(event)")
            ThreeTManager.shardInstance.openMic(isOpen: strongself.tapBtn.isSelected)
        }.disposed(by: bag)
        
        //绑定lab的文字
        tapBtn.rx.tap.map {[weak self] _ in
            self!.tapBtn.isSelected ? "你的麦克风已解除静音" :"你的麦克风已被静音"
        }
        .bind(to: lab1.rx.text)
        .disposed(by: bag)
        
        //绑定lab的textcolor
        tapBtn.rx.tap.map {[weak self] _ in
            self!.tapBtn.isSelected ? UIColor.orange : UIColor.white
        }
        .bind(to: lab1.rx.textColor)
        .disposed(by: bag)
    }
    
    

}
